package com.zijin.exec;

import java.util.Arrays;
import java.util.Scanner;

public class Text05 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入字符序列: ");
        String input = scanner.nextLine();
        char[] chars = input.toCharArray();
        Arrays.sort(chars);
        System.out.println("升序排序后: " + new String(chars));
        System.out.print("逆序输出为: ");
        for (int i = chars.length - 1; i >= 0; i--) {
            System.out.print(chars[i] + " ");
        }
        System.out.println();
        System.out.print("请输入要插入的字符: ");
        char insertChar = scanner.next().charAt(0);
        int index = 0;
        while (index < chars.length && chars[index] < insertChar) {
            index++;
        }
        char[] newChars = new char[chars.length + 1];
        System.arraycopy(chars, 0, newChars, 0, index);
        newChars[index] = insertChar;
        System.arraycopy(chars, index, newChars, index + 1, chars.length - index);
        System.out.println("插入后的字符序列: " + new String(newChars));
    }
}
